package util;

import java.io.File;
import java.io.PrintStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Constant {
    public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yy-MM-dd");
    public static final int CORE_METHODS_SIZE_BOUND = 200;
//    public final static String HEAD_TAIL_EMPTY_REGEX = "^\\s+|\\s+$";

    // 打印当前时间
    // 输出类似: 2023-04-13 14:31:02
    public static void printDateTime(PrintStream out) {
        LocalDateTime now = LocalDateTime.now();
        out.println("[" + formatter.format(now) + "]");
    }

    public static boolean isLegalPolicyFile(File x) {
        return x.getName().endsWith(".md") || x.getName().endsWith(".txt") ||
                x.getName().endsWith(".htm") || x.getName().endsWith(".html");
    }

    public static boolean isLegalApkFile(File x) {
        return x.getName().endsWith(".apk");
    }

    public static void createDirectoryIfNotExists(String targetDir) {
        File directory = new File(targetDir);
        if (!directory.exists()) {
            boolean isCreated = directory.mkdirs();
            if (isCreated) {
                System.out.println("Directory created successfully: " + targetDir);
            } else {
                System.out.println("Failed to create directory: " + targetDir);
            }
        }
    }

    public static String getApkNameFromApkFilepath(String x) {
        if (x.contains(File.separator)) {
            x = x.substring(x.lastIndexOf(File.separator) + 1);
        }
        return x.substring(0, x.length() - 4);
    }

    public static void main(String[] args) {
        String f = "C:\\Users\\Yalin Feng\\Code\\AndroidPrivacy\\Project\\data\\apk\\RQ1\\ap-news_5.17(10011).apk";
        String g = getApkNameFromApkFilepath(f);
        System.out.println(g);
    }
}
